package org.bravo369.inflightxt;

import org.bravo369.inflightxt.utils.Globals;

import android.app.TabActivity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TabHost;

public class InFlightXt extends TabActivity {
    /** Called when the activity is first created. */

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    setContentView(R.layout.main);

    TabHost tabHost = getTabHost();  // The activity TabHost
    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
    Intent intent;  // Reusable Intent for each tab

    // Create an Intent to launch an Activity for the tab (to be reused)
    intent = new Intent().setClass(this, DataCollectorView.class);
    spec = tabHost.newTabSpec("data").setIndicator("Data").setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, HudView.class);
    spec = tabHost.newTabSpec("hud").setIndicator("HUD").setContent(intent);
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, SettingsView.class);
    spec = tabHost.newTabSpec("settings").setIndicator("Settings").setContent(intent);
    tabHost.addTab(spec);

    tabHost.setCurrentTab(0);
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.menu, menu);
      return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle item selection
      switch (item.getItemId()) {
      case R.id.quit:
          Globals.getInstance().exit();
          finish();
          return true;
      default:
          return super.onOptionsItemSelected(item);
      }
  }
}